{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 抽象类\n",
    "- 抽象方法的定义：没有具体实现内容的方法\n",
    "- 抽象方法的主要意义是规范了子类的行为和接口\n",
    "- 抽象类的使用需要借助abc模块\n",
    "\n",
    "        import abc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wen yi xia\n",
      "wo shou\n"
     ]
    }
   ],
   "source": [
    "class Animal():\n",
    "    \n",
    "    def sayHello(self):\n",
    "        pass\n",
    "    \n",
    "    \n",
    "class Dog(Animal):\n",
    "    \n",
    "    def sayHello(self):\n",
    "        print('wen yi xia')\n",
    "        \n",
    "class Person(Animal):\n",
    "    \n",
    "    def sayHello(self):\n",
    "        print('wo shou')\n",
    "        \n",
    "d = Dog()\n",
    "d.sayHello()\n",
    "\n",
    "p = Person()\n",
    "p.sayHello()\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 抽象类的实现\n",
    "import abc\n",
    "\n",
    "class Humen(metaclass=abc.ABCMeta):\n",
    "    \n",
    "    # 定义一个抽象方法\n",
    "    @abc.abstractmethod\n",
    "    def smoking(self):\n",
    "        pass\n",
    "    \n",
    "    # 定义类抽象方法\n",
    "    @abc.abstractclassmethod\n",
    "    def drink():\n",
    "        pass\n",
    "    \n",
    "    # 定义静态抽象方法\n",
    "    @abc.abstractstaticmethod\n",
    "    def play():\n",
    "        pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
